Multi-Threaded Actors
نویسندگان
چکیده
p r o t e c t e d F o r k J o i n P o o l ma inExecu to r ;p r o t e c t e d P r i o r i t y B l o c k i n g Q u e u e messageQueue ;p r o t e c t e d Concur ren tL inkedQueue lockedQueue ;p r o t e c t e d P r i o r i t y B l o c k i n g Q u e u e a v a i l a b l e W o r k e r s ;p r o t e c t e d Set busyWorkers ;p r o t e c t e d Set busyData ; p u b l i c Acto r ( ) {/ / i n i t i a l i z a t i o n o f i n t e r n a l da ta s t r u c t u r e s} @Overridep u b l i c vo id run ( ) { whi le ( t rue ) {t r y {Message message = messageQueue . t a k e ( ) ;i f ( r e p o r t S y n c h r o n i z e d D a t a ( message . syncDa ta ) ) {synchronized ( busyData ) {busyData . ad dA l l ( message . syncDa ta ) ;}mainExecu to r . su bmi t ( message . f ) ;} e l s e {t h i s . lockedQueue . o f f e r (newM ) ;}} ca tch ( I n t e r r u p t e d E x c e p t i o n e ) {e . p r i n t S t a c k T r a c e ( ) ;}}} / / message f o r m a t : ()−>ge tWorker ( ) . m( )p u b l i c Fu tu re send ( O b j e c t message , Set d a t a ) {Message m = new Message ( message , da t a , name ) ;messageQueue . p u t (m) ;re turn ( Fu tu re) m. f ;} p u b l i c A c t i v e O b j e c t getNewWorker ( O b j e c t . . . p a r a m e t e r s ) {A c t i v e O b j e c t s e l e c t e d w o r k e r = n u l l ; t r y {s e l e c t e d w o r k e r = a v a i l a b l e W o r k e r s . t a k e ( ) ;busyWorkers . add ( s e l e c t e d w o r k e r ) ;} catch ( I n t e r r u p t e d E x c e p t i o n e ) {e . p r i n t S t a c k T r a c e ( ) ;} re turn s e l e c t e d w o r k e r ;} p r i v a t e boolean r e p o r t S y n c h r o n i z e d D a t a ( Set d a t a ) {Set t empSe t = new HashSet ( ) ; synchronized ( busyData ) {t empSet . a dd Al l ( busyData ) ;t empSet . r e t a i n A l l ( d a t a ) ; i f ( t empSet . i sEmpty ( ) ) {re turn true ;}re turn f a l s e ;} } p r o t e c t e d void f r e e W o r k e r ( A c t i v e O b j e c t worker , O b j e c t . . . d a t a ) { synchronized ( busyData ) {busyWorkers . remove ( worker ) ;a v a i l a b l e W o r k e r s . o f f e r ( worker ) ; messageQueue . ad dA l l ( lockedQueue ) ;lockedQueue . c l e a r ( ) ; f o r ( O b j e c t o b j e c t : d a t a ) {busyData . remove ( o b j e c t ) ;} } } p u b l i c i n t e r f a c e A c t i v e O b j e c t ex tends Comparable {/ / t h e a c t i v e o b j e c t s i n charge o f r e q u e s t s}}
منابع مشابه
Multi-agent System Simulation in Scala: An Evaluation of Actors for Parallel Simulation
Multi-agent system (MAS) simulation, a growing field within artificial intelligence, requires the creation of high-performance, parallel, and user-friendly simulation frameworks. The standard approach is to use threads and shared memory. The drawbacks of this approach are the common concurrency pitfalls of race conditions and performance loss due to synchronization. Our goal was to evaluate the...
متن کاملGenerating Multi-Threaded code from Polychronous Specifications
SIGNAL, Lustre, Esterel, and a few other synchronous programming language compilers accomplish automated sequential code generation from synchronous specifications. In generating sequential code, the concurrency expressed in the synchronous programs is sequentialized mostly because such embedded software was designed to run on single-core processors. With the widespread advent of multi-core pro...
متن کاملComparing Alternative Programming Techniques for Multi - threaded CORBA Servers ( Column 6 )
Modern OS platforms like Windows NT, and OS/2 and some flavors of UNIX provide extensive library and system call support for multi-threaded applications. However, programming multi-threaded applications is hard and programming distributed multi-threaded applications is even harder. In particular, developers must address sources of accidental and inherent complexity: Accidental complexity of mul...
متن کاملObject Interconnections Comparing Alternative Programming Techniques for Multi - threaded
Modern OS platforms like Windows NT, and OS/2 and many flavors of UNIX provide extensive library and system call support for multi-threaded applications. However, programming multi-threaded applications is hard and programming distributed multi-threaded applications is even harder. In particular, developers must address sources of accidental and inherent complexity: Accidental complexity of mul...
متن کاملObject Interconnections Comparing Alternative Programming Techniques for Multi - threaded CORBA Servers : Thread Pool ( Column 6 ) Douglas
Modern OS platforms like Windows NT, and OS/2 and many flavors of UNIX provide extensive library and system call support for multi-threaded applications. However, programming multi-threaded applications is hard and programming distributed multi-threaded applications is even harder. In particular, developers must address sources of accidental and inherent complexity: Accidental complexity of mul...
متن کاملStrategized Locking, Thread-safe Interface, and Scoped Locking Patterns and Idioms for Simplifying Multi-threaded C++ Components
Developing multi-threaded applications is hard since incorrect use of locks can cause subtle and pernicious errors. Likewise, developing multi-threaded reusable components is hard since it can be time-consuming to customize components to support new, more efficient locking strategies. This paper describes a pair of patterns, Strategized Locking and Thread-safe Interface, and a C++ idiom, Scoped...
متن کامل